home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / graphics / flip.1 next >
Text File  |  1988-11-10  |  8KB  |  235 lines

  1. Path: xanth!nic.MR.NET!hal!cwjcc!ukma!mailrus!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i060:  flip - display hack
  5. Message-ID: <10144@swan.ulowell.edu>
  6. Date: 10 Nov 88 21:51:03 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 224
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: rucklidg@svax.cs.cornell.edu (William Rucklidge)
  12. Posting-number: Volume 2, Issue 60
  13. Archive-name: graphics/flip.1
  14.  
  15. Here's a screen hack I came up with a while ago.
  16.  
  17. [binary included too, it's small.  ..Bob]
  18.  
  19. #    This is a shell archive.
  20. #    Remove everything above and including the cut line.
  21. #    Then run the rest of the file through sh.
  22. #----cut here-----cut here-----cut here-----cut here----#
  23. #!/bin/sh
  24. # shar:    Shell Archiver
  25. #    Run the following text with /bin/sh to create:
  26. #    README
  27. #    flip.c
  28. #    flip.uu
  29. # This archive created: Thu Nov 10 16:45:22 1988
  30. cat << \SHAR_EOF > README
  31.     Here's Yet Another Screen Hack I wrote in a moment of boredom.
  32. Type "flip", and observe. Try typing a few other commands, like "list".
  33. Type "flip" again to restore (or do anything which affects screen
  34. ordering/position (e.g. Left-Amiga-N)).
  35.  
  36.     For some reason or other this doesn't work reliably if you have more
  37. than the Workbench screen open. It won't crash the machine, but it won't
  38. have the desired effect.
  39.  
  40.                 - William Rucklidge
  41.                   rucklidg@svax.cs.cornell.edu
  42. SHAR_EOF
  43. cat << \SHAR_EOF > flip.c
  44. /*
  45.  * flip.c - yet another screen hack
  46.  *
  47.  * William Rucklidge    rucklidg@svax.cs.cornell.edu
  48.  *
  49.  * This code is released into the public domain. What's the point in
  50.  * copyrighting something like this, anyway?
  51.  *
  52.  * Thanks to jimm, for dcop.
  53.  *
  54.  * This will work on simple workbench screens. There seems to be some problem
  55.  * when more than one screen is open: GfxBase->ActiView doesn't seem to contain
  56.  * the right information (the copper lists and the View don't match). I'm
  57.  * probably just not looking in the right place, though.
  58.  *
  59.  * This makes some assumptions about the copper list: that the modulo registers
  60.  * are loaded before the bitplane data pointers, that the bitplane data pointers
  61.  * are loaded in successive instructions, high then low, and that the copper
  62.  * list being mangled is that of a fully displayed screen (not a window into a
  63.  * larger bitmap). These assumptions are all true for automatically generated
  64.  * copper lists.
  65.  *
  66.  * This does seem to work with vscreen'd and morerowed Workbench screen.
  67.  *
  68.  */
  69.  
  70. #include <graphics/gfxbase.h>
  71. #include <graphics/view.h>
  72. #include <graphics/copper.h>
  73.  
  74. /* The codes for a few copper instructions */
  75. #define    MOVEBPL1MOD    0x0108
  76. #define    MOVEBPL2MOD    0x010A
  77. #define    MOVEBPL1PT    0x00E0
  78.  
  79. #define    MAXPLANES    6
  80. #define    PTSKIP        4
  81.  
  82. #define    MOVEBPLPT(x)    (MOVEBPL1PT + ((x) - 1) * PTSKIP)
  83.  
  84. extern void *OpenLibrary(), CloseLibrary(), Forbid(), Permit();
  85.  
  86. struct GfxBase *GfxBase;
  87.  
  88. typedef    int    boolean;
  89. #undef    FALSE
  90. #undef    TRUE
  91. #define    FALSE    0
  92. #define    TRUE    1
  93.  
  94. void
  95. mangleCprList(list, isLOF, bpl, vy)
  96. struct cprlist *list;        /* A copper list to be mangled. */
  97. boolean isLOF;            /* Is this a LOF coppper list? */
  98. unsigned short bpl;        /* The number of bytes per line */
  99. unsigned short vy;        /* The number of lines */
  100. {
  101.     register short *cp, inst;
  102.     char *oldbplpt;
  103.     char *newbplpt;
  104.     register int i;
  105.     long offset;
  106.     boolean wasflipped = FALSE;
  107.  
  108.     if (!list) {
  109.     return;
  110.     }
  111.  
  112.     for (i = list->MaxCount, cp = (short *)list->start;
  113.      i > 0;
  114.      i--, cp += 2) {
  115.     inst = *cp;
  116.     if ((inst == MOVEBPL1MOD) || (inst == MOVEBPL2MOD)) {
  117.         /* Mangle the modulus */
  118.         if (*(cp + 1) < 0) {
  119.         wasflipped = TRUE;
  120.         }
  121.         *(cp + 1) = - (bpl << 1) - *(cp + 1);
  122.         }
  123.     else if ((inst >= MOVEBPLPT(1)) && (inst < MOVEBPLPT(MAXPLANES + 1))
  124.                     && (!(inst & 3))) {
  125.         /* This is a load bitplane address register instruction.
  126.          * Make sure that this instruction is followed by one to
  127.          * load the other half of the register
  128.          */
  129.         if ((*(cp + 2) == inst + 2) && (i > 1)) {
  130.         /* Mangle the bitplane address */
  131.         /* Pick out the address from the operands of the instructions */
  132.         oldbplpt = (char *)((((long)*(cp + 1)) << 16) +
  133.                     (unsigned short)(*(cp + 3)));
  134.         offset = (vy - 1) * (long)bpl +
  135.              (isLOF ? 0 : -((short)bpl << 1));
  136.         if (!wasflipped) {
  137.             newbplpt = oldbplpt + offset;
  138.             }
  139.         else {
  140.             newbplpt = oldbplpt - offset;
  141.             }
  142.  
  143.         /* Install the new address */
  144.         *(cp + 1) = (long)newbplpt >> 16;
  145.         *(cp + 3) = (long)newbplpt & 0xffff;
  146.         }
  147.         }
  148.     }
  149.     }
  150.  
  151. int
  152. main()
  153. {
  154.     unsigned short bpl, vy;
  155.  
  156.     GfxBase = OpenLibrary("graphics.library", 0L);
  157.     
  158.     /* We don't want anyone rebuilding the copper lists while we mangle them */
  159.     Forbid();
  160.     /* Get bytes per line and screen height */
  161.     bpl = ((GfxBase->ActiView->ViewPort->DWidth) >> 3) & ~1;
  162.     vy = GfxBase->ActiView->ViewPort->DHeight;
  163.  
  164.     mangleCprList(GfxBase->ActiView->LOFCprList, TRUE, bpl, vy);
  165.     mangleCprList(GfxBase->ActiView->SHFCprList, FALSE, bpl, vy);
  166.     Permit();
  167.  
  168.     CloseLibrary(GfxBase);
  169.     return(0);
  170.     }
  171. SHAR_EOF
  172. cat << \SHAR_EOF > flip.uu
  173.  
  174. begin 644 flip
  175. M```#\P`````````#``````````(```(>````$@````$```/I```"'D[Z`;!.!
  176. M5?_R2.<,($)M__)*K0`(9@A,WP0P3EU.=2!M``@Z*``((FT`""1I``1@``#<>
  177. M.!*X?`$(9P:X?`$*9B!*:@`";`8[?``!__(P+0`.XT!$0)!J``(U0``"8```O
  178. MJKA\`.!M``"BN'P`^&P``)HP!,!\``-F``"0,`140#(J``2R0&8``(*Z?``!A
  179. M;WHP*@`"2,!R$..@=``T*@`&T((K0/_\,"T`$%-`P.T`#B\`2FT`#&<$<`!@*
  180. M"C(M``[C03`!1$!(P"0?U(`K0O_T2FW_\F8.("W__-"M__0K0/_X8`P@+?_\Y
  181. MD*W_]"M`__@@+?_X<A#BH#5```(@+?_XP+P``/__-4``!E-%6(I*16X`_R)@"
  182. M`/\"3E7__$*G2'H`@DZZ!P103RE`@#H@;(`Z(F@`(BQ1,"X`&.9`"(```#M`O
  183. M__X@;(`Z(F@`(BQ1.VX`&O_\/RW__#\M__X_/``!(&R`.B)H`"(O*0`$3KK^*
  184. MF$_O``H_+?_\/RW__D)G(&R`.B)H`"(O*0`(3KK^>D_O``HO+(`Z3KH&0EA/_
  185. M<`!.74YU9W)A<&AI8W,N;&EB<F%R>0``87!#[(`&1>R`!K7)9@XR/``0:PATF
  186. M`"+"4<G__"E/@`8L>``$*4Z`"DCG@(`(+@`$`2EG$$OZ``A.KO_B8`9"I_-?U
  187. M3G-#^@`@3J[^:"E`@`YF#"X\``.`!TZN_Y1@!$ZZ`!I03TYU9&]S+FQI8G)A2
  188. M<GD`2?D``'_^3G5.50``+PI(>0`!```P+(`"P?P`!B\`3KH%I%!/*4"`$F84@
  189. M0J=(>0`!``!.N@5H4$\N;(`&3G4@;(`20F@`!"!L@!(Q?``!`!`B;(`2,WP`9
  190. M`0`*(&R`!B`L@`:0J``$4(`I0(`6(&R`%B"\34%.6$*G3KH%6%A/)$!*J@"LE
  191. M9RXO+0`,+RT`""\*3KH`LD_O``PY?``!@!H@;(`2`&B````$(&R`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"QL@#Y.[O^F(&\`!"QL@#Y.4
  224. M[O^R```#[`````$````!```")@````````/R```#Z@````$`%``````#\@``D
  225. *`^L````!```#\@$`E
  226. ``
  227. end
  228. size 2260
  229. SHAR_EOF
  230. #    End of shell archive
  231. exit 0
  232. -- 
  233. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  234. Have five nice days.
  235.